﻿using RimWorld;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
using Verse.AI;
using Verse.Sound;

namespace Miao.Stand
{
    /// <summary>
    /// 设置第一炸弹
    /// </summary>
    public class JobDriver_StandSetupBomb : JobDriver
    {
        /// <summary>
        /// 试着保留对象
        /// </summary>
        /// <param name="errorOnFailed"></param>
        /// <returns></returns>
        public override bool TryMakePreToilReservations(bool errorOnFailed)
        {
            return pawn.Reserve(job.targetA, job, 1, -1, null, errorOnFailed);
        }

        protected override IEnumerable<Toil> MakeNewToils()//AI部分完成
        {
            this.FailOnAggroMentalState(TargetIndex.A);
            yield return Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch);
            yield return Toils_General.Do(() =>
            {
                GenExplosion.NotifyNearbyPawnsOfDangerousExplosive(TargetThingA, DamageDefOf.Bomb , null,pawn);
            });
            yield return Toils_General.WaitWith(TargetIndex.A, 30, useProgressBar: true);
            yield return Toils_General.Do(() =>
            {
                StandSoundDefOf.KillerQueenSetup.PlayOneShot(new TargetInfo(pawn.Position, base.Map));
                (pawn as KillerQueenStand).bombTarget = TargetThingA;

            });

        }
    }
}
